#include <gtk/gtk.h>

GtkWidget *create_page_choose_finger(); // 创建手指选择页面容器及其子控件
GtkWidget *create_page_swipe_finger(); // 创建指纹登记页面容器及其子控件

static void on_activate(                // 创建主窗口并显示
						GtkApplication* app,
						gpointer user_data);

// 本程序入口点
int main (int    argc, char **argv)
{
  GtkApplication *app = NULL;
  int status = 0;

  app = gtk_application_new("net.thesct.fpreg", G_APPLICATION_FLAGS_NONE);
  g_signal_connect(app, "activate", G_CALLBACK(on_activate), NULL);
  status = g_application_run(G_APPLICATION(app), argc, argv);
  g_object_unref(app);

  return status;
}

// 创建手指选择页面容器及其子控件
GtkWidget *create_page_choose_finger()
{
  GtkWidget *vb_container = NULL; // 页面容器
  GtkWidget *cb_dev_list = NULL;  // 指纹识别器列表
  GtkWidget *img_fingers = NULL;  // 手指选择器
  GtkWidget *btn_next = NULL;     // 下一步按钮
  GtkWidget *stb_message = NULL;  // 状态栏，用于显示一些消息

  vb_container = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
  cb_dev_list = gtk_combo_box_new();
  img_fingers = gtk_image_new();
  btn_next = gtk_button_new_with_label("下一步");
  stb_message = gtk_statusbar_new();

  gtk_widget_set_halign(btn_next, GTK_ALIGN_END);
  
  gtk_box_pack_start(GTK_BOX(vb_container), cb_dev_list, FALSE, TRUE , 0);
  gtk_box_pack_start(GTK_BOX(vb_container), img_fingers, TRUE , TRUE , 0);
  gtk_box_pack_start(GTK_BOX(vb_container), btn_next   , FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vb_container), stb_message, FALSE, TRUE , 0);
  
  return vb_container;
}

// 创建指纹登记页面容器及其子控件
GtkWidget *create_page_swipe_finger()
{
  GtkWidget *vb_container = NULL; // 页面容器
  GtkWidget *img_swipe = NULL;  // 手指选择器
  GtkWidget *btn_test = NULL;     // 测试按钮
  GtkWidget *stb_message = NULL;  // 状态栏，用于显示一些消息

  vb_container = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
  img_swipe = gtk_image_new();
  btn_test = gtk_button_new_with_label("测试");
  stb_message = gtk_statusbar_new();

  gtk_widget_set_halign(btn_test, GTK_ALIGN_END);
  
  gtk_box_pack_start(GTK_BOX(vb_container), img_swipe  , TRUE , TRUE , 0);
  gtk_box_pack_start(GTK_BOX(vb_container), btn_test   , FALSE, FALSE, 0);
  gtk_box_pack_start(GTK_BOX(vb_container), stb_message, FALSE, TRUE , 0);
  
  return vb_container;
}


// 创建主窗口并显示
static void on_activate(GtkApplication* app, gpointer user_data)
{
  GtkWidget *win_main = NULL;

  GtkWidget *pg_choose_finger = NULL;
  GtkWidget *pg_swipe_finger = NULL;

  win_main = gtk_application_window_new(app);
  gtk_window_set_title(GTK_WINDOW(win_main), "指纹录入程序：");
  gtk_window_set_default_size (GTK_WINDOW(win_main), 320, 180);
  gtk_window_set_position(GTK_WINDOW(win_main),  GTK_WIN_POS_CENTER);

  pg_choose_finger = create_page_choose_finger();
  pg_swipe_finger  = create_page_swipe_finger();

  gtk_container_add(GTK_CONTAINER(win_main), pg_choose_finger);
  gtk_container_remove(GTK_CONTAINER(win_main), pg_choose_finger);
  gtk_container_add(GTK_CONTAINER(win_main), pg_swipe_finger);

  gtk_widget_show_all(win_main);
  // gtk_widget_hide(pg_choose_finger);
}
